# server.py
import http.server
import socketserver
import subprocess

from pathlib import Path
import fnmatch

def get_mapped_port():
    ss_output = subprocess.check_output(["ss","-tlnp","(listen)","sport == :8080"])
    ss_output = ss_output.decode()
    lines = ss_output.split('\n')
    for line in lines:
        if 'LISTEN' in line:
            par

# 端口号
PORT = 8080

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    msg = r"""
                                      _ooOoo_
                                     o8888888o
                                     88" . "88
                                     (| -_- |)
                                      O\ = /O
                                  ____/`---'\____
                                .   ' \\| |// `.
                                 / \\||| : |||// \
                               / _||||| -:- |||||- \
                                 | | \\\ - /// | |
                               | \_| ''\---/'' | |
                                \ .-\__ `-` ___/-. /
                             ___`. .' /--.--\ `. . __
                          ."" '< `.___\_<|>_/___.' >'"".
                         | | : `- \`.;`\ _ /`;.`/ - ` : | |
                           \ \ `-. \_ __\ /__ _/ .-` / /
                   ======`-.____`-.___\_____/___.-`____.-'======
                                      `=---='

                   .............................................
                          佛祖保佑             永无BUG
                   .............................................
    """

    print(msg)
    print("""
              *******欢迎使用由【内师开放原子开源社团】开发的简易服务器******
    """)
    print("""
    使用方法:
    1.提前把html结尾的文件放在与此软件“同级”的目录下。
    2.文件名最好不能有中文和特殊字符
    3.点击下方生成的链接即可访问！
    """)
    print("\n网址链接，点击即可访问:")
    # 获取当前文件所在目录
    current_dir = Path.cwd()  # 或者使用 Path(__file__).parent
    # 查找所有的.html文件
    html_files = current_dir.glob('*.html')
    # 遍历并打印每个找到的HTML文件的名字
    for html_file in html_files:
        print("http://localhost:8080/"+html_file.name)

    print("-------------------------------------------------------------------------->>>")
    print("软件运行日志输入:")

    httpd.serve_forever()
